<template>
  <div id="app">
    <div class="game-container">
      <div class="header">
        <h1 class="game-title">五子棋对战平台</h1>
        <div class="game-subtitle">选择对战模式</div>
      </div>

      <div class="game-cards">
        <div class="game-card" v-for="(item, index) in menuItems" :key="index">
          <router-link :to="item.path" @click="item.click" class="card-content">
            {{ item.text }}
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useUserStore } from "../stores/user";
import useNetStore from "../stores/net";

const menuItems = [
  {
    text: "联机对战",
    path: "/lobby",
    icon: "fas fa-users"
  },
  {
    text: "电脑对战",
    path: "",
    icon: "fas fa-robot"
  },
  {
    text: "本地对战",
    path: "",
    icon: "fas fa-user-friends"
  },
  {
    text: "退出登录",
    path: "",
    icon: "fas fa-sign-out-alt",
    click: handLogout
  }
];

const userStore = useUserStore();
const net = useNetStore();

function handLogout() {
  if (window.confirm("确认退出登录吗？")) {
    net
      .fasong({ userId: userStore.user.userId }, "/users/logout")
      .then((res) => {
        if (res.code === 200) {
          console.log("退出登录成功");
          userStore.logout();
        } else {
          console.log(res.msg);
        }
      })
      .catch((err) => {
        console.log(err);
      });
  }
}
</script>

<style scoped>
:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --primary-dark: #1d4ed8;
  --accent: #f59e0b;
  --text: #1e293b;
  --text-light: #f8fafc;
  --bg-opacity: 0.92;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#app {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 0)), url("../../public/backImg2.jpg") no-repeat center/cover;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.game-container {
  width: min(90%, 560px);
  padding: 3rem 2rem;
  background: rgba(255, 255, 255, var(--bg-opacity));
  border-radius: 1.5rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

.header {
  text-align: center;
  margin-bottom: 3rem;
}

.game-title {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 0.5rem;
  letter-spacing: 1px;
}

.game-subtitle {
  font-size: 1.2rem;
  color: var(--text);
  opacity: 0.8;
}

.game-cards {
  display: grid;
  gap: 1.5rem;
}

.game-card {
  position: relative;
  overflow: hidden;
  border-radius: 1rem;
  background: white;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transition: var(--transition);
  animation: fadeIn 0.5s ease-out forwards;
  opacity: 0;
}

.game-card:nth-child(1) {
  animation-delay: 0.1s;
}
.game-card:nth-child(2) {
  animation-delay: 0.2s;
}
.game-card:nth-child(3) {
  animation-delay: 0.3s;
}
.game-card:nth-child(4) {
  animation-delay: 0.4s;
}

.card-content {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: var(--transition);
  position: relative;
  /* padding-left: 4rem; */
}

.card-icon {
  position: absolute;
  left: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 1.2rem;
}

.game-card:nth-child(1) .card-content {
  background: var(--primary);
  color: var(--text-light);
}
.game-card:nth-child(2) .card-content {
  background: var(--primary-light);
  color: var(--text-light);
}
.game-card:nth-child(3) .card-content {
  background: var(--primary-dark);
  color: var(--text-light);
}
.game-card:nth-child(4) .card-content {
  background: var(--accent);
  color: var(--text-light);
}

.game-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.game-card:active {
  transform: translateY(0);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>
